﻿define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return  function ($scope,Resource,GillionMsg,GillionMsgService,$http) {
        $scope.editSign={};
        var accounts=Resource("/grule-manager/user/account");
        $http({
            method:'GET',
            url:"/grule-manager/groupUser/account"
        }).success(function(resp){
            if(resp.success==false){
                GillionMsg.alert("提示","请先登录",function(){
                    window.location.href="/html2/login/login"+"?"+window.location.href;
                });
            }else{
                $scope.account=resp.data;
            }

        });
        $scope.read=true;
        $scope.edit=function(){
            $scope.read=false;
        };
        $scope.clickInput=function(){
            $scope.read=false;
            document.getElementById("target").focus();
        }
        $scope.$watch('account.email',function(newValue,oldValue){
            if(newValue!=oldValue&&oldValue!=undefined){
                $scope.editSign=1
            }
        })
        $scope.save=function(){
            if($scope.editSign==1){
                accounts.update($scope.account,function(response){
                    if(response.success){
                        GillionMsg.alert("提示","修改成功！");
                        $scope.editSign={};
                        $scope.read=true;
                    }
                })
            }
        };
        $scope.editPassword=function(){
            GillionMsg.showUrl({
                title: '修改密码',
                url: '/html2/system/account/updatePassword',
                width: 400,
                height: 300,
                data:$scope.account,
                onClose: function (resp) {
                    if (resp.success) {
                        GillionMsg.alert("提示", "密码修改成功");
                        $http({
                            method:'GET',
                            url:"/grule-manager/groupUser/account"
                        }).success(function(resp){
                            $scope.account=resp.data;
                        })
                    }
                }
            });
        };


    }
});